﻿using Model;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;

namespace Zellularautomat
{
	/// <summary>
	/// Interaktionslogik für UCAttributes.xaml
	/// </summary>
	public partial class UCAttributes : UserControl
	{
		Cell cell;

		public Cell Cell
		{
			get { return cell; }
			set { cell = value; ChangeUI(); }
		}

		public UCAttributes()
		{
			InitializeComponent();
		}

		private void ChangeUI()
		{
			panel.Children.Clear();
			Label l = new Label()
			{
				Content = "Attribute für " + cell.CellDefinition.Name,
				FontSize = 14,
				FontWeight = FontWeights.Bold,
				Margin = new System.Windows.Thickness(5)
			};
			panel.Children.Add(l);
			foreach (var attribute in cell.Attributes)
			{
				AddAttribute(attribute);
			}
		}

		private void AddAttribute(KeyValuePair<string, Attribut> attribute)
		{
			if (attribute.Value is StringAttribut)
				panel.Children.Add(new UCStringAttribute(attribute.Key, cell));
			if (attribute.Value is NumberAttribut)
				panel.Children.Add(new UCNumericAttribute(attribute.Key, cell));
		}

	}
}